
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0854
 * @Author : WangRuoyu 
 * @Date : 2023/5/22 15:42
 */

#include "iostream"

using namespace std;

int main() {
    int n, m, q;
    const int inf = 0x3f3f3f3f;
    scanf("%d %d %d", &n, &m, &q);

    int d[n + 1][n + 1];
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i == j) {
                d[i][j] = 0;
            } else {
                d[i][j] = inf;
            }
        }
    }

    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        d[a][b] = min(d[a][b], c);
    }

    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    for (int i = 0; i < q; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        if (d[a][b] > 1e8) {
            printf("impossible\n");
        } else {
            printf("%d\n", d[a][b]);
        }
    }

    return 0;
}